package com.scut.dispatching_server.service;

import com.scut.dispatching_server.config.GlobalVariables;
import com.scut.dispatching_server.model.Supplier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

@Component
public class SupplierPost {
    @Autowired
    private RestTemplate restTemplate;
    public boolean addSupplier(Supplier supplier) {
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        String url = GlobalVariables.DEMO_ADDRESS + GlobalVariables.DEMO_SUPPLIER_ADD_PATH;
        HttpEntity<Supplier> entity = new HttpEntity<>(supplier, headers);
        restTemplate.postForEntity(url, entity, String.class);
        return true;
    }
}
